/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import entity.Users;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import sessionbeans.UsersFacade;

/**
 *
 * @author Axel
 */
@ManagedBean(name="ListUserBean")
@RequestScoped
public class ListUserBean {

    @EJB
    private UsersFacade uf;

    @ManagedProperty(value="#{userBean}") // #{user} is the managed bean name
    private sessionUserBean userBean;

    private List<Users> listOfUsers;

    /** Creates a new instance of ListUserBean */
    public ListUserBean() {
    }

    @PostConstruct
    public void init(){
        this.setListOfUsers(this.getUf().findAll());
    }

    /**
     * @return the listOfUsers
     */
    public List<Users> getListOfUsers() {
        return listOfUsers;
    }

    public String follow(Users aUser){
        this.getUserBean().getUser().getFollow().add(aUser);
        return "profile";
    }

    /**
     * @param listOfUsers the listOfUsers to set
     */
    public void setListOfUsers(List<Users> listOfUsers) {
        this.listOfUsers = listOfUsers;
    }

    /**
     * @return the uf
     */
    public UsersFacade getUf() {
        return uf;
    }

    /**
     * @param uf the uf to set
     */
    public void setUf(UsersFacade uf) {
        this.uf = uf;
    }

    /**
     * @return the userBean
     */
    public sessionUserBean getUserBean() {
        return userBean;
    }

    /**
     * @param userBean the userBean to set
     */
    public void setUserBean(sessionUserBean userBean) {
        this.userBean = userBean;
    }

}
